<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<P>
<H2>Owners:</H2>
<script type="text/javascript">
// use the loading message for DWR
    dwr.util.useLoadingMessage();

function searchOwners() {
 var surname = dwr.util.byId('lastName').value;
 
 dwr.util.removeAllRows('ownerTableBody');
 DwrClinic.findOwners(surname, function(owners) {
	var rowCreator =[
	function(owner) {return owner.displayableName},
	function(owner) {return owner.address},
	function(owner) {return owner.city},
	function(owner) {return owner.telephone},
	function(owner) {
			var pets = owner.pets;
			var petStr = [];
			var i;
			for( i=0;i<pets.length;i++) {
				var pet = pets[i];
				petStr.push(pet.name);
			}
	return petStr.join(' ')}
	];
	
	dwr.util.addRows('ownerTableBody',owners, rowCreator);  
 });
}
</script>
<form onsubmit="searchOwners();return false;">
<input type="text" id="lastName"> <a href="javascript:searchOwners()">Search</a>
</form>
<TABLE border="1" id="ownerTable">
<thead>
<tr>
  <TH>Name</TH><TH>Address</TH><TH>City</TH><TH>Telephone</TH><TH>Pets</TH>
  </tr>
  </thead>
  <tbody id="ownerTableBody"></tbody>
</TABLE>

<P>
<BR>
<%@ include file="/WEB-INF/jsp/footer.jsp" %>
